﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GreenPark
{
    public partial class frmCihaz : Form
    {
        public frmCihaz()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Cihaz chz = null;
            if (cmbNo.SelectedIndex > -1)
            {
                chz = (Cihaz)cmbNo.SelectedItem;
                chz.Tanim = txtTanim.Text;
                chz.IpAdresi = txtadres.Text;
                chz.Tip = Convert.ToByte(cmbTip.SelectedIndex);
                chz.KayitKapisi = chkKayit.Checked;
            }
            else
            {
                chz = new Cihaz();
                chz.No = Convert.ToInt32(cmbNo.Text);
                chz.Tanim = txtTanim.Text;
                chz.IpAdresi = txtadres.Text;
                chz.Tip = Convert.ToByte(cmbTip.SelectedIndex);
                chz.KayitKapisi = chkKayit.Checked;
                Program.Db.Cihazlar.Add(chz);
            }
            this.Close();
        }

        private void frmCihaz_Load(object sender, EventArgs e)
        {
            cmbTip.SelectedIndex = 0;
            foreach (Cihaz item in Program.Db.Cihazlar)
            {
                cmbNo.Items.Add(item);
            }
        }

        private void cmbNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbNo.SelectedIndex > -1)
            {
                Cihaz chz = (Cihaz)cmbNo.SelectedItem;
                txtTanim.Text = chz.Tanim;
                txtadres.Text = chz.IpAdresi;

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (cmbNo.SelectedIndex > -1)
            {
                Cihaz chz = (Cihaz)cmbNo.SelectedItem;
                Program.Db.Cihazlar.Remove(chz);
                this.Close();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            cmbNo.SelectedIndex = -1;
            txtadres.Text = "";
            txtTanim.Text = "";
            cmbTip.SelectedIndex = 0;
        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
